//
//  SDNetImageView.m
//  图像处理
//
//  Created by 李志权 on 15/3/25.
//  Copyright (c) 2015年 李志权. All rights reserved.
//

#import "SDNetImageView.h"

@implementation SDNetImageView

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(self.width/2-15,self.highly/2-15, 30, 30)] ;
        self.activity.backgroundColor = [UIColor clearColor];//设置背景透明
        self.activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;//设置样式
        self.activity.hidesWhenStopped = NO;//动画停止时是否隐藏,YES隐藏 NO不隐藏，默认是YES
        self.activity.color = GreenColor;
        [self.activity startAnimating];
        [self addSubview:self.activity];
        self.userInteractionEnabled = YES;
    }
    return self;
}

/**
 @功能：设置imageURL加载网络图片
 @参数：无
 @返回值：无
 */
- (void)setImageURL:(NSString *)imageURL
{
    if (![imageURL hasPrefix:@"http://"])
        imageURL = [NSString stringWithFormat:@"http://%@", imageURL];
    
    if (_imageURL != imageURL)
    {
        _imageURL = imageURL;
        if (!_imageURL) return;
        
        [self sd_setImageWithURL:[NSURL URLWithString:self.imageURL] placeholderImage:[UIImage imageNamed:self.defaultIMG] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            
            [self.activity removeFromSuperview];
         
        }];
    }
}

@end
